﻿//Created by Action Script Viewer - http://www.buraks.com/asv
		//用法：
		/*public function initStage(){
			this.stageinfo = new StageInfo();
			STW = this.stageinfo.stageW;
			STH = this.stageinfo.stageH;
			this.stageinfo.addFun(bgFit);
		}
		private function bgFit() {
			bg.x = (this.stageinfo.stageW - bg.width) / 2 + bg.width / 2;
			bg.y = (this.stageinfo.stageH - bg.height) / 2 + bg.height / 2;
			bg.scaleX  = (this.stageinfo.stageW / _ww);
			bg.scaleY = (this.stageinfo.stageH / _hh)
			trace("STW:"+STW)
		}*/

package org.nickro.project{
    import flash.events.*;
    import flash.display.*;
	import org.nickro.project.Global;

    public class StageInfo {
		//适应屏幕类
        private var _stageW:Number;
        private var _stageH:Number;
        private var _refreshFun:Array;
        private var _mainRoot;

        public function StageInfo() {
            this._refreshFun = new Array();//把适就的函数方法存在数组中.
            super();
            this._mainRoot = Global._globalRoot;
            this._mainRoot.stage.scaleMode = StageScaleMode.NO_SCALE;
            this._mainRoot.stage.align = StageAlign.TOP_LEFT;
            this.stageRefresh();
            this._mainRoot.stage.addEventListener(Event.RESIZE, this.stageResize);
        }
        //把需在适应的对象的函数添加进来，适应场景。
        public function addFun(_arg1:Function):void{
            _arg1();
            this._refreshFun.push(_arg1);
        }
        public function removeFun(_arg1:Function):void{
            var _local2:int = this._refreshFun.length;
            var _local3:int;
            while (_local3 < _local2) {
                if (this._refreshFun[_local3] == _arg1){
                    this._refreshFun.splice(_local3, 1);
                };
                _local3++;
            };
        }
		//场景刷新.
        private function stageRefresh():void{
            this._stageW = this._mainRoot.stage.stageWidth;
            this._stageH = this._mainRoot.stage.stageHeight;
			
            var _local1:int = this._refreshFun.length;//数组长度.
            var _local2:int;
            while (_local2 < _local1) {
                if (this._refreshFun[_local2] != null){
                    var _local3 = this._refreshFun;
                    _local3[_local2]();
                };
                _local2++;
            };
        }
        private function stageResize(_arg1:Event):void{
            this.stageRefresh();
        }
		//得场景宽和高
		public function get stageW():Number{
            return (this._stageW);
        }
        public function get stageH():Number{
            return (this._stageH);
        }
    }
}
